﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace SVN.Net.Misc
{
    public class SVNExportResult : ActionResult
    {
        public byte[] Content
        {
            get;
            private set;
        }

        public string Name
        {
            get;
            private set;
        }

        public SVNExportResult(string name, byte[] content)
            : base()
        {
            Name = name;
            Content = content;
        }

        public override void ExecuteResult(ControllerContext context)
        {
            HttpContext hc = HttpContext.Current;
            hc.Response.Clear();
            hc.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}.zip\";", Name));
            hc.Response.Charset = "";
            hc.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            hc.Response.ContentType = "application/octet-stream";
            hc.Response.BinaryWrite(Content);
            hc.Response.End();
        }
    }
}
